Component({
  properties: {
    mode: {
      type: Number,
      value: 1,
    },
    orderId: String,
    orderStatus: {
      type: Number,
      value: 1,
    },
    refundId: String,
    refundTotalAmount: Number,
    applyRefundParams: Object,
    localNo: String,
    reasonName: String,
    douYinPayJson: Object,
    remark: String,
    fileList: Array,
    phone: String,
    workSecondPrice: Number,
    goodsType: Number,
  },
  //   observers: {
  //     applyRefundParams(newInfo, oldInfo) {
  //       if (!newInfo) return;
  //       console.log("父组件applyRefundParams更新了：", applyRefundParams);
  //       // 处理最新数据
  //       this.setData({
  //         applyRefundParams: {
  //           ...newInfo,
  //         },
  //       });
  //     },
  //   },
  data: {},
  methods: {
    // bind:refund 使用示例
    handleRefund(event) {
      const { status, result } = event.detail;
      if (status === "success") {
        const { refundId, outRefundNo } = result;
        console.log(refundId, outRefundNo, "退款单号!!!!!!!!!!!");
      } else {
        const { errMsg } = result;
        console.log(errMsg, "退款回调报错原因。。");
      }
    },
    // bind:applyrefund 使用示例
    applyRefund(event) {
      console.log("canIUse", tt.canIUse("industrySDK.pay-button"));
      console.log("onApplyrefund", event, this.properties);
      // this.properties.douYinPayJson.item_order_info_list = [
      //          {itemOrderId:'800012214619328256213652387'}
      //      ]
      console.log(
        "团购品/预约品抖音itemOrderList ",
        this.properties.douYinPayJson.item_order_info_list
      );
      // 判断是否支持行业sdk 的 pay-button 组件
      if (tt.canIUse("industrySDK.pay-button")) {
        // do something
        console.log("industrySDK.pay-button canIUse");
      }
      const { orderId } = event.detail;
      // 预约品
      const refundRelatedOrderDetail = [
        {
          orderImmediate: orderId, //创建预约单的预约单号
          refundAmount: 0, //预约单默认无金额
          // deductFeeAmount: 0, //
        },
      ];
      // 非预约品(团购品)
      const goodsDetail = [
        {
          itemOrderId: orderId,
        },
      ];
      // 开发者需要透传的参数，可自定义内容
      const extra = {
        orderId,
        orderTotalPrice: this.properties.douYinPayJson.total_amount,
        workSecondPrice: this.properties.workSecondPrice,
        // itemOrderList: this.properties.douYinPayJson.item_order_info_list, // 预约品传,非预约品(团购品) 不可传
        // goodsDetail, // 非预约品(团购品)传
        // refundRelatedOrderDetail, // 预约品传
      };
      // goodsType 0.团购 1.预约
      if (this.properties.goodsType == 0) {
        extra.goodsDetail = goodsDetail; // 非预约品(团购品)传
        delete extra.itemOrderList;
        delete extra.refundRelatedOrderDetail;
      }
      if (this.properties.goodsType == 1) {
        extra.itemOrderList =
          this.properties.douYinPayJson.item_order_info_list; // 预约品传,非预约品(团购品) 不可传
        extra.refundRelatedOrderDetail = refundRelatedOrderDetail; // 预约品传
        delete extra.goodsDetail;
      }
      console.log("退款extra~~~~~~~~~~", extra);

      return new Promise((resolve) => {
        resolve(extra);
        // tt.navigateBack({
        //   delta: 1,
        // });
      });
    },

    // bind:applyrefund 使用示例
    _applyRefund(event) {
      console.log("canIUse", tt.canIUse("industrySDK.pay-button"));
      console.log("onApplyrefund", event, this.properties);
      // this.properties.douYinPayJson.item_order_info_list = [
      //          {itemOrderId:'800012214619328256213652387'}
      //      ]
      console.log(
        "团购品/预约品抖音itemOrderList ",
        this.properties.douYinPayJson.item_order_info_list
      );
      // 判断是否支持行业sdk 的 pay-button 组件
      if (tt.canIUse("industrySDK.pay-button")) {
        // do something
        console.log("industrySDK.pay-button canIUse");
      }
      const { orderId } = event.detail;
      // 预约品
      const refundRelatedOrderDetail = [
        {
          orderImmediate: orderId, //创建预约单的预约单号
          refundAmount: 0, //预约单默认无金额
          // deductFeeAmount: 0, //
        },
      ];
      // 非预约品(团购品)
      const goodsDetail = [
        {
          itemOrderId: orderId,
        },
      ];
      // 开发者需要透传的参数，可自定义内容
      const extra = {
        orderId,
        //// localNo: this.properties.localNo,
        //// reasonName: this.properties.reasonName,
        orderTotalPrice: this.properties.douYinPayJson.total_amount, // $data.info.firstTotalPrice,
        //// reasonContent: this.properties.remark,
        //// img: this.properties.fileList.map((m) => m.file.data[0].url).join(","),
        //// phone: this.properties.phone,
        workSecondPrice: this.properties.workSecondPrice,
        // itemOrderList: this.properties.douYinPayJson.item_order_info_list, // 预约品传,非预约品(团购品) 不可传
        goodsDetail, // 非预约品(团购品)传
        // refundRelatedOrderDetail, // 预约品传
      };
      return new Promise((resolve) => {
        resolve(extra);
        // tt.navigateBack({
        //   delta: 1,
        // });
      });
      //   const { orderId } = event.detail;
      //   const itemOrderList = [
      //     {
      //       itemOrderId: "800011994652859213013388216",
      //       refundAmount: 9000,
      //       deductFeeAmount: 0,
      //       refundRelatedItemType: 2,
      //     },
      //   ];
      //   const refundRelatedOrderDetail = [
      //     {
      //       orderId: "800011994652859238616028216",
      //       refundAmount: 0,
      //       deductFeeAmount: 0,
      //     },
      //   ];
      //   const isRefundRelatedOrderOnly = true; //只退加价单传

      //   const extra = {
      //     orderId,
      //     itemOrderList,
      //     refundRelatedOrderDetail,
      //   };
      //   // 开发者需要透传的参数，可自定义内容
      //   console.log(extra);
      //   return new Promise((resolve) => {
      //     resolve(extra);
      //   });
    },

    // 错误信息含义见下文 bind:error报错信息
    handleError(event) {
      const { errMsg, errNo } = event.detail;
      tt.showToast({
        title: `[${errNo}]${errMsg}`,
        icon: "none",
        mask: true,
      });
      console.log(errMsg, errNo, "报错了！！！");
      console.log("onPayButtonSdkError", event);
    },
  },
});
